version 15      // Stata version control

clear all          // clear memory

macro drop _all    // delete all macros

set linesize 82    // result window has room for 82 chars in one line

set more off, perm // prevents pause in results windowversion 12

*********set global paths


/*instructions:
*set up folder structure including a data, tables, and figure folder
*insert dataset "full_data.dta" into "data" folder

*specify globals for paths

global path1 "YOUR_FOLDER_PATH/data"

global path2 "YOUR_FOLDER_PATH/tables"

global path3 "YOUR_FOLDER_PATH/figures"

*from here on the do-file should produce the results and put them in the respective folders


***load data */

use $path1/full_data.dta, clear



*create lagged 
gen l_adjcov=. // margins doesn't work with depednent variable on right hand side, thus cannot include lag using time operators
replace l_adjcov=adjcov[_n-1] if country==country[_n-1]



********************
***descriptive figures for introduction
********************

*Figure 1 (for bargaining coverage and inequality)

graph tw (scatter gini adjcov, mcolor(black) msize(small)) ///
	(lfitci gini adjcov, lcolor(black) color(gray%40)), ///
	ytitle("Gini (post taxes and transfers)", color(black) size(small)) ///
	xtitle("Bargaining Coverage", color(black) size(small)) ///
	ylabel(,labsize(small)) ///
	xlabel(,labsize(small)) ///
	plotregion(style(none))  ///                                   
	graphregion(fc(white) lc(white)) ///
	legend(off) ///
	saving($path3/figure_bc_gini.gph, replace)

graph export $path3/figure_bc_gini.pdf, replace	
graph export $path3/figure_bc_gini.tif, replace	

*Figure 2 (for union density and bargaining coverage over time by country)

graph twoway (line adjcov year, lpattern(solid) lcolor(black)) ///
	(line ud year, lpattern(dash) lcolor(black)), ///
	legend(order(1 "Bargaining" "Coverage" 2 "Union" "Density") col(1) row(2) size(large) ) ///
	xtitle("") ///
	by(id, legend(pos(0) at(22)) note("") ///
	plotregion(style(none))  ///                                   
	graphregion(fc(white) lc(white))) ///
	subtitle(,fc(white) lc(white) size(large) pos(12) ring(0) nobexpand) ///
	saving($path3/figure_bc_ud.gph, replace)
	
graph export $path3/figure_bc_ud.pdf, replace
graph export $path3/figure_bc_ud.tif, replace


**************
*****multivariate analyses
**************

sort cnt year //sort data by country and year

***set panel structure
xtset cnt year


		
		
***Error correction models	

*specify global for covariates
global covars "c.d1.(z_off_merge z_indperc z_loggdp z_leftgov z_fed z_unempr z_capopen z_tradeopen z_wc_rights z_strike_right z_org_right z_coord z_ud) c.l1.(z_off_merge l1.z_indperc z_loggdp z_leftgov z_fed z_unempr z_capopen z_tradeopen z_wc_rights z_strike_right z_org_right z_coord z_ud)"


*first run full model to define final sample, constrain sample to non-missing, listwise delete

xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext ///
	c.d1.z_rte_merge#c.d1.z_ext  c.d1.z_rte_merge#c.l1.z_ext ///
	c.l1.z_rte_merge#c.l1.z_ext c.l1.z_rte_merge#c.d1.z_ext $covars i.year, fe cluster(cnt)

gen sample = e(sample)	

*random effects model with wave dummies

xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext i.year if sample==1, re cluster(cnt)
estimates store ecm_re_wave_no_cov

xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext ///
	c.d1.z_rte_merge#c.d1.z_ext  c.d1.z_rte_merge#c.l1.z_ext ///
	c.l1.z_rte_merge#c.l1.z_ext c.l1.z_rte_merge#c.d1.z_ext i.year if sample==1, re cluster(cnt)
estimates store ecm_int_re_wave_no_cov


*random effects model with wave dummies and full set of covariates	
		
xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext $covars i.year if sample==1, re cluster(cnt)
estimates store ecm_re_wave_cov

xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext ///
	c.d1.z_rte_merge#c.d1.z_ext  c.d1.z_rte_merge#c.l1.z_ext ///
	c.l1.z_rte_merge#c.l1.z_ext c.l1.z_rte_merge#c.d1.z_ext $covars i.year if sample==1, re cluster(cnt)
estimates store ecm_int_re_wave_cov

*fixed effects model with wave dummies and full set of covariates	
		
xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext $covars i.year if sample==1, fe cluster(cnt)
estimates store ecm_fe_wave_cov

xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext ///
	c.d1.z_rte_merge#c.d1.z_ext  c.d1.z_rte_merge#c.l1.z_ext ///
	c.l1.z_rte_merge#c.l1.z_ext c.l1.z_rte_merge#c.d1.z_ext $covars i.year if sample==1, fe cluster(cnt)
estimates store ecm_int_fe_wave_cov	

margins, dydx(d1.z_rte_merge) at(d1.z_ext=-1 l1.z_ext=-1) post
estimates store low_ext

xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext ///
	c.d1.z_rte_merge#c.d1.z_ext  c.d1.z_rte_merge#c.l1.z_ext ///
	c.l1.z_rte_merge#c.l1.z_ext c.l1.z_rte_merge#c.d1.z_ext $covars i.year if sample==1, fe cluster(cnt)
margins, dydx(d1.z_rte_merge) at(d1.z_ext=0 l1.z_ext=0) post
estimates store med_ext

xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext ///
	c.d1.z_rte_merge#c.d1.z_ext  c.d1.z_rte_merge#c.l1.z_ext ///
	c.l1.z_rte_merge#c.l1.z_ext c.l1.z_rte_merge#c.d1.z_ext $covars i.year if sample==1, fe cluster(cnt)
margins, dydx(d1.z_rte_merge) at(d1.z_ext=1 l1.z_ext=1) post
estimates store high_ext

coefplot (low_ext, levels(95) ciopts(recast(. rcap) lcolor(black black)) msymbol(d) mlcolor(black) mfcolor(white)) ///
		(med_ext, levels(95) ciopts(recast(. rcap) lcolor(black black)) msymbol(d) mlcolor(black) mfcolor(black)) ///
         (high_ext, levels(95) ciopts(recast(. rcap) lcolor(black black)) msymbol(d) mlcolor(black) mfcolor(gray%40)),  ///
		yline(0, lstyle(foreground)) vertical xtitle("") xlabel("") ///
		graphregion(color(white)) legend(order(2 "low extension" 4 "mean extension" 6 "high extension") row(1)) ///
		ytitle ("Bargaining Coverage (%)") ylabel(-20(10)20, notick labsize(medsmall)) ///
		bgcolor(white) saving($path3/figure_effplot, replace)

graph export $path3/figure_effplot.pdf, replace	
graph export $path3/figure_effplot.tif, replace			


outreg2 [ecm_re_wave_no_cov ecm_int_re_wave_no_cov ecm_re_wave_cov ///
		ecm_int_re_wave_cov ecm_fe_wave_cov ecm_int_fe_wave_cov] using $path2/Table1 , replace excel word tex ///
		alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) ///
		keep(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext cD.z_rte_merge#cD.z_ext cD.z_rte_merge#cL.z_ext ///
		cL.z_rte_merge#cD.z_ext  cL.z_rte_merge#cL.z_ext) ///
		sortvar(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext cD.z_rte_merge#cD.z_ext cD.z_rte_merge#cL.z_ext ///
		cL.z_rte_merge#cD.z_ext  cL.z_rte_merge#cL.z_ext) ///
		paren() bdec(3) sdec(3) nor2 label(lower)	

		
		
*****************************		
******Robustness checks
**************************
		
*jackknifing

forval i = 1/21 {
	xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext  i.year if cnt!=`i' & sample==1, re cluster(cnt)
	estimates store re_wave_no_cov_jk_`i'
	xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext ///
	c.d1.z_rte_merge#c.d1.z_ext  c.d1.z_rte_merge#c.l1.z_ext ///
	c.l1.z_rte_merge#c.l1.z_ext c.l1.z_rte_merge#c.d1.z_ext i.year if cnt!=`i' & sample==1, re cluster(cnt)
	estimates store int_re_wave_no_cov_jk_`i'
	xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext $covars  i.year if cnt!=`i' & sample==1, re cluster(cnt)
	estimates store re_wave_cov_jk_`i'
	xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext ///
	c.d1.z_rte_merge#c.d1.z_ext  c.d1.z_rte_merge#c.l1.z_ext ///
	c.l1.z_rte_merge#c.l1.z_ext c.l1.z_rte_merge#c.d1.z_ext $covars i.year if cnt!=`i' & sample==1, re cluster(cnt)
	estimates store int_re_wave_cov_jk_`i'
	xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext $covars  i.year if cnt!=`i' & sample==1, fe cluster(cnt)
	estimates store fe_wave_cov_jk_`i'
	xtreg d1.adjcov l_adjcov c.d1.z_rte_merge c.l1.z_rte_merge c.d1.z_ext c.l1.z_ext ///
	c.d1.z_rte_merge#c.d1.z_ext  c.d1.z_rte_merge#c.l1.z_ext ///
	c.l1.z_rte_merge#c.l1.z_ext c.l1.z_rte_merge#c.d1.z_ext $covars i.year if cnt!=`i' & sample==1, fe cluster(cnt)
	estimates store int_fe_wave_cov_jk_`i'
	}
	
	
	
outreg2 [re_wave_no_cov_jk_*] using $path2/re_wave_no_cov_jk , replace excel word tex ///
		alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) ///
		keep(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext) ///
		sortvar(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext) ///
		paren() bdec(3) sdec(3) nor2 label(lower)
		
outreg2 [int_re_wave_no_cov_jk_*] using $path2/int_re_wave_no_cov_jk , replace excel word tex ///
		alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) ///
		keep(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext cD.z_rte_merge#cD.z_ext cD.z_rte_merge#cL.z_ext ///
		cL.z_rte_merge#cD.z_ext  cL.z_rte_merge#cL.z_ext) ///
		sortvar(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext cD.z_rte_merge#cD.z_ext cD.z_rte_merge#cL.z_ext ///
		cL.z_rte_merge#cD.z_ext  cL.z_rte_merge#cL.z_ext)  ///
		paren() bdec(3) sdec(3) nor2 label(lower)		
					
outreg2 [re_wave_cov_jk_*] using $path2/re_wave_cov_jk , replace excel word tex ///
		alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) ///
		keep(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext) ///
		sortvar(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext) ///
		paren() bdec(3) sdec(3) nor2 label(lower)
		
outreg2 [int_re_wave_cov_jk_*] using $path2/int_re_wave_cov_jk , replace excel word tex ///
		alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) ///
		keep(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext cD.z_rte_merge#cD.z_ext cD.z_rte_merge#cL.z_ext ///
		cL.z_rte_merge#cD.z_ext  cL.z_rte_merge#cL.z_ext) ///
		sortvar(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext cD.z_rte_merge#cD.z_ext cD.z_rte_merge#cL.z_ext ///
		cL.z_rte_merge#cD.z_ext  cL.z_rte_merge#cL.z_ext)  ///
		paren() bdec(3) sdec(3) nor2 label(lower)		
		
outreg2 [fe_wave_cov_jk_*] using $path2/fe_wave_cov_jk , replace excel word tex ///
		alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) ///
		keep(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext) ///
		sortvar(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext) ///
		paren() bdec(3) sdec(3) nor2 label(lower)
		
outreg2 [int_fe_wave_cov_jk_*] using $path2/int_fe_wave_cov_jk , replace excel word tex ///
		alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +) ///
		keep(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext cD.z_rte_merge#cD.z_ext cD.z_rte_merge#cL.z_ext ///
		cL.z_rte_merge#cD.z_ext  cL.z_rte_merge#cL.z_ext) ///
		sortvar(l_adjcov D1.z_rte_merge L1.z_rte_merge D1.z_ext L1.z_ext cD.z_rte_merge#cD.z_ext cD.z_rte_merge#cL.z_ext ///
		cL.z_rte_merge#cD.z_ext  cL.z_rte_merge#cL.z_ext)  ///
		paren() bdec(3) sdec(3) nor2 label(lower)		

		
		
exit





